
// =============================================================================
// ============================ Summary Stats ==================================
// ============================== Table 1 ======================================
//==============================================================================

// Births subset

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1 & inrange(year, 2008, 2011)

capture log close

log using "~/Documents/Research/output/Malpractice/summaryStatsBirths" , replace

// Number of hospitals

sort treat facility_id
by treat facility_id, sort: gen nvals = _n == 1

//FL
count if nvals==1 & treat==0

distinct facility_id if treat==0

//NC
count if nvals==1 & treat==1

distinct facility_id if treat==1

// FL Summary Stats

summarize year facility_id white medicaid private otherIns compHypertension overweightObese diabetes c_section code72 drugInduce otherObProc agey procedureCount  losdays treat allDeliv if treat==0, separator(4)

// NC Summary Stats

summarize year facility_id white medicaid private otherIns compHypertension overweightObese diabetes c_section code72 drugInduce otherObProc agey procedureCount  losdays treat allDeliv if treat==1, separator(4)

summarize c_section if medicaid==1

summarize c_section if private==1

log close

// =============================================================================
// =================== Full Diff-in-Diff - log file ============================
// ====================== Table 2 & Table 3 ====================================
//==============================================================================

// C-Section - run at the individual level =====================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat

capture log close

log using "~/Documents/Research/output/Malpractice/event_study" , replace

//Without FE
reg c_section i.treat##ib2011.year 	          , cluster(facility_id)	
	
//With FE
areg c_section i.treat##ib2011.year 	      , absorb(facility_id) cluster(facility_id)

log close

log using "~/Documents/Research/output/Malpractice/diff_in_diff" , replace

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg c_section i.dd i.year i.treat		  	 , cluster(facility_id)		

//With FE
areg c_section i.dd i.year i.treat			 , absorb(facility_id) cluster(facility_id)	

log close

// Code 72 OB Proc - run at the individual level =============================

clear

local github https://raw.githubusercontent.com
net install pretrends, from(`github'/mcaceresb/stata-pretrends/main) replace

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white code72 treat

capture log close

log using "~/Documents/Research/output/Malpractice/event_study" , append

//Without FE
reg code72 i.treat##ib2011.year 			, cluster(facility_id)		

//With FE
areg code72 i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

matrix list e(b)

pretrends power 0.5,  pre(23/26) post(27/32)

return list

log close

log using "~/Documents/Research/output/Malpractice/diff_in_diff" , append

// code72 - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg code72 i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg code72 i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close

// drugInduce - run at the individual level ===========================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white drugInduce treat

capture log close

log using "~/Documents/Research/output/Malpractice/event_study" , append

//Without FE
reg drugInduce i.treat##ib2011.year 			, cluster(facility_id)		

//With FE
areg drugInduce i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

matrix list e(b)

pretrends power 0.5,  pre(23/26) post(27/32)

return list

log close

log using "~/Documents/Research/output/Malpractice/diff_in_diff" , append

// drugInduce - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg drugInduce i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg drugInduce i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close


// otherObProc - run at the individual level ===========================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white otherObProc treat

capture log close

log using "~/Documents/Research/output/Malpractice/event_study" , append

//Without FE
reg otherObProc i.treat##ib2011.year 			, cluster(facility_id)		

//With FE
areg otherObProc i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

log close

log using "~/Documents/Research/output/Malpractice/diff_in_diff" , append

// otherObProc - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg otherObProc i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg otherObProc i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close


// =============================================================================
// ======================== Insurance Groups ===================================
// ===========================  Table 4 ========================================
// =============================================================================

// Insurance - Private - run at the individual level ===============================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1 & private==1

keep facility_id year private medicaid otherIns agey white c_section treat

capture log close

log using "~/Documents/Research/output/Malpractice/insurance" , replace

// Insurance - Private

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg c_section i.dd i.year i.treat		  	 , cluster(facility_id)		

//With FE
areg c_section i.dd i.year i.treat			 , absorb(facility_id) cluster(facility_id)	

log close

// Insurance - Medicaid - run at the individual level =============================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1 & medicaid==1

keep facility_id year private medicaid otherIns agey white c_section treat

capture log close

log using "~/Documents/Research/output/Malpractice/insurance" , append

// Insurance - Medicaid

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg c_section i.dd i.year i.treat		  	 , cluster(facility_id)		

//With FE
areg c_section i.dd i.year i.treat			 , absorb(facility_id) cluster(facility_id)	

log close


// =============================================================================
// ====================== Patient Characteristics ==============================
// ========================== Table 5 ==========================================
// =============================================================================

// Age - run at the individual level ==========================================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat

capture log close

log using "~/Documents/Research/output/Malpractice/did_c_sec_pt_char" , replace

// Age - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg agey i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg agey i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close

// White - run at the individual level ==========================================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat

capture log close

log using "~/Documents/Research/output/Malpractice/did_c_sec_pt_char" , append

// White - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg white i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg white i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		
log close

// Hypertension - run at the individual level ===================================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat compHypertension

capture log close

log using "~/Documents/Research/output/Malpractice/did_c_sec_pt_char" , append

// Hypertension - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg compHypertension i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg compHypertension i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close

// Obese - run at the individual level ==========================================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat overweightObese

capture log close

log using "~/Documents/Research/output/Malpractice/did_c_sec_pt_char" , append

// Obese - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg overweightObese i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg overweightObese i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close

// Diabetes - run at the individual level =======================================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat diabetes

capture log close

log using "~/Documents/Research/output/Malpractice/did_c_sec_pt_char" , append

// Diabetes - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg diabetes i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg diabetes i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close

// Length of Stay - run at the individual level ================================

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat losdays

capture log close

log using "~/Documents/Research/output/Malpractice/did_c_sec_pt_char" , append

// Length of Stay - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg losdays i.dd i.year i.treat 			   	, cluster(facility_id)

//With FE
areg losdays i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

log close


// =============================================================================
// ======================== Insurance Groups ===================================
// ======================== Appendix Table 3 ===================================
// =============================================================================

// C-Section - run at the individual level - CHOW TEST =========================

clear

capture log close

log using "~/Documents/Research/output/Malpractice/CT_diff_in_diff" , replace

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat


// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

// Break is: private
// Break interactions are: ddPrivate yearPrivate treatPrivate

gen ddPrivate = dd*private

gen yearPrivate = year*private

gen treatPrivate = treat*private

//Without FE
reg c_section i.dd i.year i.treat i.private i.ddPrivate i.yearPrivate i.treatPrivate    , cluster(facility_id)		

//With FE
areg c_section i.dd i.year i.treat i.private i.ddPrivate i.yearPrivate i.treatPrivate	, absorb(facility_id) cluster(facility_id)	

log close


*******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************

// =============================================================================
// ============== Full Diff-in-Diff - EXCEL SPREADSHEET ========================
// ====================== Table 2 & Table 3 ====================================
//==============================================================================

// C-Section ===================================================================

// C-Section - run at the individual level =====================================

clear

cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

//Without FE
reg c_section i.treat##ib2011.year 	          , cluster(facility_id)		

outreg2 using event_study.xls, replace

//With FE
areg c_section i.treat##ib2011.year 	      , absorb(facility_id) cluster(facility_id)

outreg2 using event_study.xls, append

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg c_section i.dd i.year i.treat		  	 , cluster(facility_id)	

outreg2 using diff_in_diff.xls, replace	

//With FE
areg c_section i.dd i.year i.treat			 , absorb(facility_id) cluster(facility_id)	

outreg2 using diff_in_diff.xls, append

// Code 72 OB Proc - run at the individual level ===================================

clear

cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white code72 treat

cd "~/Documents/Research/output/Malpractice"

//Without FE
reg code72 i.treat##ib2011.year 			, cluster(facility_id)	

outreg2 using event_study.xls, append	

//With FE
areg code72 i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

outreg2 using event_study.xls, append

// code72 - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg code72 i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using diff_in_diff.xls, append

//With FE
areg code72 i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using diff_in_diff.xls, append

// drugInduce - run at the individual level ==========================

clear

cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white drugInduce treat

cd "~/Documents/Research/output/Malpractice"

//Without FE
reg drugInduce i.treat##ib2011.year 			, cluster(facility_id)	

outreg2 using event_study.xls, append	

//With FE
areg drugInduce i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

outreg2 using event_study.xls, append

// drugInduce - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg drugInduce i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using diff_in_diff.xls, append

//With FE
areg drugInduce i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using diff_in_diff.xls, append

// otherObProc - run at the individual level ==========================

clear

cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white otherObProc treat

cd "~/Documents/Research/output/Malpractice"

//Without FE
reg otherObProc i.treat##ib2011.year 			, cluster(facility_id)	

outreg2 using event_study.xls, append	

//With FE
areg otherObProc i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

outreg2 using event_study.xls, append

// otherObProc - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg otherObProc i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using diff_in_diff.xls, append

//With FE
areg otherObProc i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using diff_in_diff.xls, append

// =============================================================================
// ======================== Insurance Groups ===================================
// ===========================  Table 4 ========================================
// =============================================================================

// Insurance - Private - run at the individual level ===============================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1 & private==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg c_section i.dd i.year i.treat		  	 , cluster(facility_id)	

outreg2 using insurance.xls, replace	

//With FE
areg c_section i.dd i.year i.treat			 , absorb(facility_id) cluster(facility_id)	

outreg2 using insurance.xls, append

// Insurance - Medicaid - run at the individual level =============================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1 & medicaid==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg c_section i.dd i.year i.treat		  	 , cluster(facility_id)	

outreg2 using insurance.xls, append	

//With FE
areg c_section i.dd i.year i.treat			 , absorb(facility_id) cluster(facility_id)	

outreg2 using insurance.xls, append


// =============================================================================
// ====================== Patient Characteristics ==============================
// ========================== Table 5 ==========================================
// =============================================================================

// Age - run at the individual level ==========================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// Age - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg agey i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_c_sec_pt_char.xls, replace

//With FE
areg agey i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		
outreg2 using did_c_sec_pt_char.xls, append

// White - run at the individual level ==========================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// White - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg white i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_c_sec_pt_char.xls, append

//With FE
areg white i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		
outreg2 using did_c_sec_pt_char.xls, append

// Hypertension - run at the individual level =====================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat compHypertension

cd "~/Documents/Research/output/Malpractice"

// Hypertension - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg compHypertension i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_c_sec_pt_char.xls, append

//With FE
areg compHypertension i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_c_sec_pt_char.xls, append

// Obese - run at the individual level ==========================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat overweightObese

cd "~/Documents/Research/output/Malpractice"

// Obese - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg overweightObese i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_c_sec_pt_char.xls, append

//With FE
areg overweightObese i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_c_sec_pt_char.xls, append

// Diabetes - run at the individual level =======================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat diabetes

cd "~/Documents/Research/output/Malpractice"

// Diabetes - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg diabetes i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_c_sec_pt_char.xls, append

//With FE
areg diabetes i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_c_sec_pt_char.xls, append

// Length of Stay - run at the individual level =======================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if c_section==1

keep facility_id year private medicaid otherIns agey white c_section treat losdays

cd "~/Documents/Research/output/Malpractice"

// Length of Stay - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg losdays i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_c_sec_pt_char.xls, append

//With FE
areg losdays i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_c_sec_pt_char.xls, append


// =============================================================================
// ======================== Insurance Groups ===================================
// ======================== Appendix Table 3 ===================================
// =============================================================================

// C-Section - run at the individual level - CHOW TEST =========================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// C-Section - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

// Break is: private
// Break interactions are: ddPrivate yearPrivate treatPrivate

gen ddPrivate = dd*private

gen yearPrivate = year*private

gen treatPrivate = treat*private

//Without FE
reg c_section i.dd i.year i.treat i.private i.ddPrivate i.yearPrivate i.treatPrivate    , cluster(facility_id)	

outreg2 using CT_diff_in_diff.xls, replace	

//With FE
areg c_section i.dd i.year i.treat i.private i.ddPrivate i.yearPrivate i.treatPrivate	, absorb(facility_id) cluster(facility_id)	

outreg2 using CT_diff_in_diff.xls, append	


// =============================================================================
// ====================== Patient Characteristics ==============================
// ======================= Appendix Table 4 ====================================
// ================= ALL PATIENTS - NOT LIMITED TO C-SECTION ===================
// =============================================================================


// Age - run at the individual level ==========================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// Age - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg agey i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_allDeliv_pt_char.xls, replace

//With FE
areg agey i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		
outreg2 using did_allDeliv_pt_char.xls, append

// White - run at the individual level ==========================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat

cd "~/Documents/Research/output/Malpractice"

// White - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg white i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_allDeliv_pt_char.xls, append

//With FE
areg white i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		
outreg2 using did_allDeliv_pt_char.xls, append

// Hypertension - run at the individual level ==================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat compHypertension

cd "~/Documents/Research/output/Malpractice"

// Hypertension - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg compHypertension i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_allDeliv_pt_char.xls, append

//With FE
areg compHypertension i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_allDeliv_pt_char.xls, append

// Obese - run at the individual level ==========================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat overweightObese

cd "~/Documents/Research/output/Malpractice"

// Obese - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg overweightObese i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_allDeliv_pt_char.xls, append

//With FE
areg overweightObese i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_allDeliv_pt_char.xls, append

// Diabetes - run at the individual level =======================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat diabetes

cd "~/Documents/Research/output/Malpractice"

// Diabetes - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg diabetes i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_allDeliv_pt_char.xls, append

//With FE
areg diabetes i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_allDeliv_pt_char.xls, append


// Length of Stay - run at the individual level ================================

clear
		
cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat losdays

cd "~/Documents/Research/output/Malpractice"

// Length of Stay - treat x post

gen post = (year >=2012)

gen dd = 0
replace dd = 1 if treat==1 & post==1

//Without FE
reg losdays i.dd i.year i.treat 			   	, cluster(facility_id)

outreg2 using did_allDeliv_pt_char.xls, append

//With FE
areg losdays i.dd i.year i.treat 			   	, absorb(facility_id) cluster(facility_id)		

outreg2 using did_allDeliv_pt_char.xls, append


// =============================================================================
// ========================= Financial Calculation =============================
// ============================== Table 6 ======================================
// =============================================================================

clear

cd "~/Desktop"

use NC_and_FL_inpt_mini_08to17, clear

keep if state=="NC"

capture log close

log using "~/Documents/Research/output/Malpractice/financialCalculation" , replace

//Births in NC in 2011
tab allDeliv if year==2011
tab allDeliv if year==2011 & private==1
tab allDeliv if year==2011 & medicaid==1 

//2011 Count of C-Sections
tab c_section if year==2011
tab c_section if year==2011 & private==1
tab c_section if year==2011 & medicaid==1

//C-Section Cost
sum totchg if year==2011 & c_section==1
sum totchg if year==2011 & c_section==1 & private==1
sum totchg if year==2011 & c_section==1 & medicaid==1

keep if allDeliv==1

//Non-C-Section Cost
sum totchg if year==2011 & c_section!=1
sum totchg if year==2011 & c_section!=1 & private==1
sum totchg if year==2011 & c_section!=1 & medicaid==1

log close